﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Vision.VisionWorkshop.Common
{
	internal class OpacityBoolConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			string modifier = "null";
			double opacity = .6;

			if (parameter != null)
			{
				string[] args = parameter.ToString().Split(',');
				//&& parameter.ToString() == "!null")
				for (int i = 0; i < args.Length; i++)
				{
					if (args[i] == "null" || args[i] == "!null")
						modifier = args[i];
					else
						double.TryParse(args[i], out opacity);
				}

				if (modifier == "null")
					return (value == null ? opacity : 1);
				else
					return (value != null ? opacity : 1);
			}
			else
				return value;
		}

		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			return value;
		}
	}
}
